package com.example.demo2.controller;

import com.example.demo2.common.config.web.WLResult;
import com.example.demo2.common.jwt.DefaultToken;
import com.example.demo2.entity.SecurityUser;
import com.example.demo2.entity.SysUser;
import com.example.demo2.entity.User;
import com.example.demo2.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@RestController
@RequestMapping("user")
@AllArgsConstructor
@Api(tags = {"用户"})
public class UserController {


    private final UserService userService;


    @ApiOperation("用户登陆")
    @PostMapping("/login")
    public Object login(@RequestBody SysUser user){
        return userService.login(user);
    }


    @ApiOperation("用户登陆")
    @PostMapping("/register")
    public void register(@RequestBody SysUser user){
        userService.register(user);
    }





    @ApiOperation("获取用户信息")
    @GetMapping("/getUserInfo")
    @PreAuthorize("hasAuthority(@securityService.privilege)")
    public Object getUserInfo(){
       return userService.getUserInfo();
    }


    @Service("securityService")
    class SecurityService {
        public String getPrivilege(){
            return "CREATE_USER_PRIVILEGE";
        }

    }
}
